package com.yz.fanrenmianshi.model.dto.questionbankquestion;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 批量移除题目从题库的结果
 */
@Data
public class BatchRemoveResult {
    /**
     * 总数
     */
    private int total;
    
    /**
     * 成功数量
     */
    private int successCount;
    
    /**
     * 失败数量
     */
    private int failureCount;
    
    /**
     * 失败原因列表
     */
    private List<String> failureReasons = new ArrayList<>();
    
    /**
     * 跳过数量（不存在的题目）
     */
    private int skipCount;
    
    /**
     * 跳过的题目ID列表
     */
    private List<Long> skipQuestionIds = new ArrayList<>();
    
    /**
     * 处理是否成功
     */
    private boolean success;
    
    /**
     * 处理消息
     */
    private String message;
    
    public BatchRemoveResult() {
        this.failureReasons = new ArrayList<>();
        this.skipQuestionIds = new ArrayList<>();
    }
    
    /**
     * 添加失败原因
     */
    public void addFailureReason(String reason) {
        this.failureReasons.add(reason);
        this.failureCount++;
    }
    
    /**
     * 添加跳过的题目ID
     */
    public void addSkipQuestionId(Long questionId) {
        this.skipQuestionIds.add(questionId);
        this.skipCount++;
    }
    
    /**
     * 增加成功数量
     */
    public void incrementSuccessCount() {
        this.successCount++;
    }
    
    /**
     * 计算处理结果
     */
    public void calculateResult() {
        this.success = this.failureCount == 0;
        if (this.success) {
            if (this.skipCount > 0) {
                this.message = String.format("批量删除完成，成功：%d，跳过：%d（不存在）", this.successCount, this.skipCount);
            } else {
                this.message = String.format("批量删除完成，成功：%d", this.successCount);
            }
        } else {
            this.message = String.format("批量删除完成，成功：%d，失败：%d，跳过：%d", this.successCount, this.failureCount, this.skipCount);
        }
    }
}